import CryptoJS from "crypto-js";
const Decrypt = (str, key1, iv1) => {
  let key = CryptoJS.enc.Utf8.parse(key1);
  let iv = CryptoJS.enc.Utf8.parse(iv1);
  let encryptedHexStr = CryptoJS.enc.Hex.parse(str);
  let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
  let decrypt = CryptoJS.AES.decrypt(srcs, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
  return decryptedStr.toString();
};
//加密方法
const Encrypt = (str, key1, iv1) => {
  let key = CryptoJS.enc.Utf8.parse(key1);
  let iv = CryptoJS.enc.Utf8.parse(iv1);
  let srcs = CryptoJS.enc.Utf8.parse(str);
  let encrypted = CryptoJS.AES.encrypt(srcs, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  return encrypted.ciphertext.toString().toUpperCase();
};
let $X = {
  Decrypt,
  Encrypt,
};
export default $X;
